package com.amado.springboot.springbootcms.service.impl;

import com.amado.commons.PageRequest;
import com.amado.springboot.springbootcms.entity.CmsDept;
import com.amado.springboot.springbootcms.entity.CmsDeptExample;
import com.amado.springboot.springbootcms.mapper.CmsDeptMapper;
import com.amado.springboot.springbootcms.service.CmsDeptService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author wangyulong-910
 * @date 2019年7月28日下午11:39:31
 */
@Service
public class CmsDeptServiceImpl implements CmsDeptService {
    @Autowired
    private CmsDeptMapper mapper;

    /**
     * 插入
     * @author wangyulong-910
     * @date 2019年7月28日下午11:39:31
     */
    @Override
    public void insert(CmsDept record) {
        mapper.insert(record);
    }

    /**
     * 根据ID修改
     * @author wangyulong-910
     * @date 2019年7月28日下午11:39:31
     */
    @Override
    public void updateById(CmsDept record) {
        mapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 删除
     * @author wangyulong-910
     * @date 2019年7月28日下午11:39:31
     */
    @Override
    public void deleteById(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据ID查找
     * @author wangyulong-910
     * @date 2019年7月28日下午11:39:31
     */
    @Override
    public CmsDept getById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    /**
     * 查询
     * @author wangyulong-910
     * @date 2019年7月28日下午11:39:31
     */
    @Override
    public PageInfo<CmsDept> list(PageRequest pageRequest) {
        //TODO
        CmsDeptExample example = new CmsDeptExample();
        if (pageRequest.getOrderBy()!=null) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(pageRequest.getOrderBy());
            if (pageRequest.getSort()!=null) {
                stringBuilder.append(" ").append(pageRequest.getSort());
            }
            example.setOrderByClause(stringBuilder.toString());
        }
        return PageHelper.startPage(pageRequest.getOffset(),pageRequest.getLimit()).doSelectPageInfo(()->mapper.selectByExample(example));
    }
}